main(n,x,s,y)
{
	char a[100][100];
	for(gets(a);~scanf("%d",&n);printf("%d\n",s))
	{
		for(x=100;x;memset(a[--x],0,100));
		
		for(;n--;){
			scanf("%d%d",&x,&y);
			for(s=10;s--;memset(&a[x+s][y],1,10));
		}
		
		for(s=x=0;x<10000;s+=a[x/100][x++%100]);
	}
}
